package com.algorithms.techniques;

import com.algorithms.techniques.RedBlackBinarySearchTree.Color;
import java.util.Random;

import org.junit.Before;
import org.junit.Test;

public class TestBSTree 
{
	BinarySearchTree<Integer,Integer> tree=null; 
	@Before
	public void generateTree()
	{
		tree = new BinarySearchTree<Integer,Integer>();
	}
	@Test
	public void insertToTree()
	{
		Random random  =new Random();
		int minimum=100;
		int number =0;
		for(int i =0;i<5;i++)
		{
			number= minimum + random.nextInt(20);
			tree.insertIntegerInTree(tree, number);
		}
		//tree.inorderWalk(tree.getRoot());
	}
	
	@Test
	public void deleteFromTree()
	{
		
	}
	
	@Test
	public void searchTree()
	{
		int[] arrayInt = new int[]{4,8,6,2,4,5};
		for(int num :arrayInt)
		{
			tree.insertIntegerInTree(tree, num);	
		}
		//System.out.println(tree.searchNode(4));
	}
	
	@Test
	public void findSmallest()
	{
		int[] arrayInt = new int[]{4,8,6,2,4,1};
		for(int num :arrayInt)
		{
			tree.insertIntegerInTree(tree, num);	
		}
		
		//System.out.println("Smallest=" + tree.findSmallestFromNodeDown(tree.searchNode(4)));
	}
	@Test
	public void findSuccessor()
	{
		int[] arrayInt = new int[]{4,8,6,2,4,1,9,7,3};
		for(int num :arrayInt)
		{
			tree.insertIntegerInTree(tree, num);	
		}
		//System.out.println("Successor="+tree.findSuccessor(3));
	}
	@Test
	public void deleteKey()
	{
		BinarySearchTree<Double,Double> treeD=new BinarySearchTree<Double,Double>(); 
		double[] arrayInt = new double[]{4,8,6,2,4,1,9,7,3,7.5};
		for(double num :arrayInt)
		{
			Node<Double,Double> nodeD= new Node<Double,Double>();
			nodeD.setKey(num);
			nodeD.setValue(num);
			treeD.insertInTree( nodeD);	
		}
		treeD.deleteKey(6.0);
		//treeD.inorderWalk(treeD.getRoot());
	}
	
	@Test
	public void inorderWalkTree()
	{
		int[] arrayInt = new int[]{4,8,6,2,4,1};
		for(int num :arrayInt)
		{
			tree.insertIntegerInTree(tree, num);	
		}
		//tree.inorderWalk(tree.getRoot());
	}
	@Test
	public void rbTreeInsert()
	{
		RedBlackBinarySearchTree<Double,Double> treeD=new RedBlackBinarySearchTree<Double,Double>(); 
		double[] arrayDouble = new double[]{4,8,6,2,4,1,9,7,3,7.5};
		try
		{
			for(double num :arrayDouble)
			{
				//treeD.createARBNode(num, num, Color.RED);
				treeD.insertInTree( treeD.createARBNode(Double.valueOf(num), Double.valueOf(num), Color.RED));	
			}
		} catch (Throwable e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		treeD.inorderWalk(treeD.getRoot());
	}
	
}
